#ifndef __LIB_GUI_WINDOW_H
#define __LIB_GUI_WINDOW_H

#include <stddef.h>
#include <stdbool.h>
#include <sys/list.h>
#include "gui_spirit.h"
#include "gui_view.h"
#include "gui_timer.h"

typedef enum
{
    GUI_WINDOW_ACTIVE = (1 << 1),        // window active
    GUI_WINDOW_SHOW = (1 << 2),          // window show
    GUI_WINDOW_MAX = (1 << 3),           // window maximum
    GUI_WINDOW_ENABLERESIZE = (1 << 4),  // window resizeable enable
    GUI_WINDOW_DISABLERESIZE = (1 << 5), // window resizeable disable
} gui_window_status_t;

typedef enum
{
    GUI_WINDOW_TOPLEVEL = 0, // top window
    GUI_WINDOW_POPUP,        // pop window
} gui_window_type_t;

#define GUI_WINDOW_WIDTH_DEFAULT 800
#define GUI_WINDOW_HEIGHT_DEFAULT 600

#define GUI_WINDOW_ICON_MSG_NAME "taskbar_icon"

#define GUI_WINDOW_ICON_BIG 1 //window switch icon
#define GUI_WINDOW_ICON_MIDDLE 2 //taskbar show icon
#define GUI_WINDOW_ICON_SMALL 3  

#define GUI_WINDOW_BTN_SIZE 14 //btn size 

typedef struct 
{
    int border_thick; //border width
    int navigation_height; //navigation_height
    uview_color_t background_color_active;
    uview_color_t background_color_inactive;
    uview_color_t front_color_active;
    uview_color_t front_color_inactive;
    uview_color_t border_color_active;
    uview_color_t border_color_inactive;
    uview_color_t text_color_active;
    uview_color_t text_color_inactive;
}gui_window_style_t;

typedef enum{
    GUI_WIN_POS_NONE=0, //no fixed
    GUI_WIN_POS_CENTER, //center
    GUI_WIN_POS_MOUSE, //show in mouse pos
    GUI_WIN_POS_CENTER_ALWAYS, //window always center
}gui_window_position_t;

typedef struct 
{
    gui_spirit_t *title;
    gui_spirit_t *maximum;
}gui_window_navigation_t;

typedef void (*gui_window_routine_t)(gui_spirit_t*,uview_msg_t *);
typedef void (*gui_window_paint_callback_t)(gui_spirit_t*,gui_rect_t *);

typedef struct 
{
    gui_spirit_t spirit;
    gui_spirit_t window_spirit;
    int content_width;
    int content_height;
    gui_window_style_t *style;
    uint32_t winflags;
    gui_window_navigation_t navigation;
    gui_window_type_t type;
    gui_window_routine_t routine;
    gui_window_paint_callback_t paint_callback;
    gui_rect_t backup_win_info;
    gui_rect_t invalid_rect;
    list_t timer_list_head; //timer
    gui_surface_t mmap_surface; 
    void *extension;
    int icon_msgid; //taskbar icon message queue
}gui_window_t;


#define GUI_WINDOW(spirit) ((gui_window_t*)(spirit))


void gui_window_calc_content_size(gui_window_t *window, int vwidth, int vheight, int *cwidth, int *cheight);
void gui_window_calc_view_size(gui_window_t *window, int cwidth, int cheight, int *vheight, int *vwidht);
int gui_mouse_filter_msg(gui_spirit_t *spirit, uview_msg_t *msg);
int gui_keyboard_filter_msg(gui_spirit_t *spirit, uview_msg_t *msg);
int gui_window_filter_msg(gui_window_t *window, uview_msg_t *msg);
int gui_window_main(gui_spirit_t *spirit, uview_msg_t *msg);
int gui_window_draw_border(gui_window_t *window, int is_active, int win_back);
int gui_window_draw_no_border(gui_window_t *window);
void gui_window_close_show(gui_spirit_t *spirit);
void gui_window_minimum_show(gui_spirit_t *spirit);
void gui_window_maximum_show(gui_spirit_t *spirit);
gui_spirit_t *gui_window_create(gui_window_type_t type);
gui_spirit_t *gui_window_create_simple(char *title, int x, int y, int width, int height);
int gui_window_invalid_rect(gui_window_t *window, gui_rect_t *rect);
int gui_window_invalid_window(gui_window_t *window);
int gui_window_get_invalid(gui_window_t *window, gui_rect_t *rect);
int gui_window_paint(gui_window_t *window);
int gui_window_show(gui_window_t *window);
int gui_window_set_icon(gui_window_t *window, const char *path, int type);
int gui_window_spirit_setup(gui_window_t *window, gui_spirit_t *spirit, int x, int y, int width, int height);
int gui_window_spirit_setdown(gui_spirit_t *spirit);
int gui_window_view_setup(gui_window_t *window, int x, int y, int width, int height);
int gui_window_view_setdown(gui_window_t *window);
int gui_window_paint_callback(gui_window_t *window, gui_window_paint_callback_t callback);
int gui_window_destroy(gui_window_t *window);
int gui_window_set_title(gui_window_t *window, char *title);
int gui_window_set_resizeable(gui_window_t *window, bool resizeable);
int gui_window_set_monitor(gui_window_t *window, bool monitor);
int gui_window_reset_mobile_area(gui_window_t *window);
gui_surface_t *gui_window_get_surface(gui_window_t *window);
gui_surface_t *gui_window_get_mmap_surface(gui_window_t *window);
int gui_window_flip(gui_window_t *window);
int gui_window_update(gui_window_t *window, int x, int y, int w, int h);
int gui_window_refresh(gui_window_t *window, int x, int y, int w, int h);
int gui_window_set_position(gui_window_t *window, gui_window_position_t pos);
int gui_window_set_default_size(gui_window_t *window, int width, int height);
int gui_window_set_routine(gui_window_t *window, gui_window_routine_t routine);
int gui_window_set_active(gui_window_t *window, bool is_active);
int gui_window_set_fixed(gui_window_t *window, bool fixed);
int gui_window_set_size_minimum(gui_window_t *window, int width, int height);
int gui_window_get_screen(gui_window_t *window, int width, int height);
int gui_window_resize_to_screen(gui_window_t *window);
int gui_window_load_mouse_cursor(gui_window_t *window, char *path);
int gui_window_set_position_absolute(gui_window_t *window, int x, int y);
int gui_window_get_position(gui_window_t *window, int *x, int *y);
int gui_window_enable_maximum(gui_window_t *window);
int gui_window_disable_maximum(gui_window_t *window);
int gui_window_set_maximum_rect(gui_window_t *window, gui_rect_t *rect);
int gui_window_get_maximum_rect(gui_window_t *window, gui_rect_t *rect);
int gui_window_maximum(gui_window_t *window);
int gui_window_maximum_selete(gui_window_t *window);
int gui_window_minimum(gui_window_t *window);
int gui_window_restore(gui_window_t *window);
uint32_t gui_window_add_timer(gui_window_t *window,uint32_t interval,gui_timer_callback_t func,void *data);
int gui_window_remove_timer(gui_window_t *window,uint32_t timer_id);
int gui_window_restart_timer(gui_window_t *window,uint32_t timer_id,int interval);
int gui_window_mmap(gui_window_t *window);
int gui_window_munmap(gui_window_t *window);
int gui_window_mmap_resize(gui_window_t *window,int width,int height);




#endif